package util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Tools {
	public static byte[] getBytesFromFile(File file) throws IOException {
		InputStream is = new FileInputStream(file); // 获得文件尺寸        
		long length = file.length(); // 不能使用类型为long的数组       // 需要为int型        // 在转换成一个int型前必须确保文件尺寸大于 Integer.MAX_VALUE.         
		if (length > Integer.MAX_VALUE) { // 文件尺寸若太大        
			
		} // 创建字节数组保存数据       
		byte[] bytes = new byte[(int) length]; // 读取字节        
		int offset = 0;
		int numRead = 0;
		while (offset < bytes.length
				&& (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
			offset += numRead;
		} // 确保所有字节被读取        
		if (offset < bytes.length) {
			throw new IOException("Could not completely read file "
					+ file.getName());
		} // 关闭输入流，返回字节       
		is.close();
		return bytes;
	}
	 public static synchronized void unzip(String zipFileName, String extPlace) throws Exception {  
	        try {  
	            (new File(extPlace)).mkdirs();  
	            File f = new File(zipFileName);  
	            ZipFile zipFile = new ZipFile(zipFileName);  
	            if((!f.exists()) && (f.length() <= 0)) {  
	                throw new Exception("要解压的文件不存在!");  
	            }  
	            String strPath, gbkPath, strtemp;  
	            File tempFile = new File(extPlace);  
	            strPath = tempFile.getAbsolutePath();  
	            java.util.Enumeration e = zipFile.entries();  
	            while(e.hasMoreElements()){  
	                ZipEntry zipEnt = (ZipEntry) e.nextElement();  
	                gbkPath=zipEnt.getName();  
	                if(zipEnt.isDirectory()){  
	                    strtemp = strPath + File.separator + gbkPath;  
	                    File dir = new File(strtemp);  
	                    dir.mkdirs();  
	                    continue;  
	                } else {  
	                    //读写文件  
	                    InputStream is = zipFile.getInputStream(zipEnt);  
	                    BufferedInputStream bis = new BufferedInputStream(is);  
	                    gbkPath=zipEnt.getName();  
	                    strtemp = strPath + File.separator + gbkPath;  
	                  
	                    //建目录  
	                    String strsubdir = gbkPath;  
	                    for(int i = 0; i < strsubdir.length(); i++) {  
	                        if(strsubdir.substring(i, i + 1).equalsIgnoreCase("/")) {  
	                            String temp = strPath + File.separator + strsubdir.substring(0, i);  
	                            File subdir = new File(temp);  
	                            if(!subdir.exists())  
	                            subdir.mkdir();  
	                        }  
	                    }  
	                    FileOutputStream fos = new FileOutputStream(strtemp);  
	                    BufferedOutputStream bos = new BufferedOutputStream(fos);  
	                    int c;  
	                    while((c = bis.read()) != -1) {  
	                        bos.write((byte) c);  
	                    }  
	                    bos.close();  
	                    fos.close();  
	                }  
	            }  
	        } catch(Exception e) {  
	            e.printStackTrace();  
	            throw e;  
	        }  
	    }  
	public static void main(String[] args){
		System.out.println(Integer.MAX_VALUE);
	}

}
